<template>
  <div>
    <cropper @success="success" />
  </div>
</template>

<script setup lang="ts">
import cropper from '@/components/cropper/home.vue'
import { setUserInfo } from '@/api/login';
import storage from '@/utils/storage';
const userInfo = ref<any>('')

// 此方法为上传图片成功之后的回调
async function success(url: string) {
  userInfo.value.face = url
  const res = await setUserInfo(userInfo.value)
  if (!res.data.success) {
    uni.showToast({
      title: "修改失败!",
      icon: "none"
    })
  } else {
    uni.showToast({
      title: "修改成功!",
      icon: "none"
    })
    setTimeout(() => {
      uni.navigateBack()
    }, 500);
  }
}

onMounted(() => {
  userInfo.value = storage.getUserInfo()
})
</script>

<style scoped></style>
